<!DOCTYPE html>
<html>
<head>
    {include file="../application/common/header.html" /}
    <script src="__STATIC__/js/echarts-3.8.4.js"></script>
</head>

<body>
    <h4 align="center" style="color:#060">教师任教班级的所教学科的实力排名走势图<br />（{$teacherName}）</h4>
    <p align="center" id="choices"></p>
    <div id="teacherScoreChart" style="width:100%;height:550px; margin:0 auto 20px auto;"></div>
    
    <script type="text/javascript">
        var teacherName = "{$teacherName}";
        var url = "/examScore/exam_chart_teacher";
        $(function(){
            loadReport();
        }) 
        function loadReport() {
            $.ajax({
               url: url + "/pageQuery.html",
               type: "POST",
               data: {
                  teacherName:teacherName,
                  rows: 500
               }
            }).done(function(data) {
                var rspData = data["rows"];
                var categoryList = [];
                var emptyCategory = [];
                var classData = [];
                for(var i in rspData) {
                    if(!classData[rspData[i].班级ID]) {
                        classData[rspData[i].班级ID] = [];
                        classData[rspData[i].班级ID].clazz = rspData[i].班级ID;
                    }
                    if(!categoryList[rspData[i].考试ID]) {
                        categoryList[rspData[i].考试ID] = [];
                        categoryList[rspData[i].考试ID] = 
                                rspData[i].学期名称+ 
                                rspData[i].考试名称;
                        emptyCategory[rspData[i].考试ID] = [];
                        emptyCategory[rspData[i].考试ID] = null;
                    }
                }
                for(var i in rspData) {
                    var cd = classData[rspData[i].班级ID];
                    if(cd) {
                        if(cd.data == null) {
                            cd.data = cloneArray(emptyCategory);
                        }
                        cd.data[rspData[i].考试ID] = rspData[i].实力排名;
                    }
                }
                totalTermExamReport(categoryList, classData);
            })
        }
        var examTemp = [];
        function totalTermExamReport(categoryList, classData) {
            examTemp = categoryList;
            //基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('teacherScoreChart'));
            option = {
                tooltip: {
                    trigger: 'axis'
                },
                grid: {
                    hoverable:true,
                    top: 100,
                    bottom: '45%'
                },
                legend: {
                    data: (function () {
                        var list = [];
                        for(var i in classData) {
                            list.push(classData[i].clazz+"班");
                        }
                        return list;
                    })()
                },
                dataZoom: [{
                    show: true,
                    realtime: true,
                    start: 0,
                    end: 100
                }],
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: getArray(categoryList),
                    name: "考试",
                    axisLabel: {interval: 0, rotate: 82}
                },
                yAxis: {
                    type: 'value',
                    name: "排名",
                    inverse: true,
                    min: 1,
                    nameLocation: 'start'
                },
                series: (function () {
                    var list = [];
                    for(var i in classData) {
                        list.push({
                            name: classData[i].clazz+"班",
                            type:'line',
                            data: getArray(classData[i].data)
                        })
                    }
                    return list;
                })()
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
        function getArray(list) {
            var array = [];
            for(var i in list) {
                array.push(list[i]);
            }
            return array;
        }

        function cloneArray(obj) {  
            var o;  
            if (typeof obj == "object") {  
                if (obj === null) {  
                    o = null;  
                } else {  
                    if (obj instanceof Array) {  
                        o = []; 
                        for (var j in obj) {
                            o[j] = clone(obj[j]);  
                        }   
                    } else {  
                        o = {};  
                        for (var j in obj) {
                            if(obj[j] == undefined) continue;
                            o[j] = clone(obj[j]);  
                        }  
                    }  
                }  
            } else {  
                o = obj;  
            }  
            return o;  
        }
        function clone(obj) {
          // Handle the 3 simple types, and null or undefined
          if (null == obj || "object" != typeof obj) return obj;
         
          // Handle Date
          if (obj instanceof Date) {
            var copy = new Date();
            copy.setTime(obj.getTime());
            return copy;
          }
         
          // Handle Array
          if (obj instanceof Array) {
            var copy = [];
            for (var i = 0, len = obj.length; i < len; ++i) {
              copy[i] = clone(obj[i]);
            }
            return copy;
          }
         
          // Handle Object
          if (obj instanceof Object) {
            var copy = {};
            for (var attr in obj) {
              if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
            }
            return copy;
          }
         
          throw new Error("Unable to copy obj! Its type isn't supported.");
        }
    </script>
</body>
</html>